package com.longge;

import java.util.ArrayList;
import java.util.List;

/**
 * @创建人 xinglongge
 * @创建时间 2021/12/1
 * @描述
 */
public class FindTarget {

    private List<Integer> vals = new ArrayList<Integer>();

    public boolean findTarget(TreeNode root, int k) {
        dfs(root);
        for (int i = 0; i < vals.size(); i++) {
            int j = k - vals.get(i);
            if (dpt(i + 1, vals, j)) return true;
        }
        return false;
    }

    public boolean dpt(int i, List<Integer> vals, int v) {
        int j = vals.size() - 1;
        while (i <= j) {
            int mid = (i + j) / 2;
            if (vals.get(mid) == v) return true;
            if (vals.get(mid) < v) {
                i = mid + 1;
                System.out.println(i);
                System.out.println(j);
            } else {
                j = mid - 1;
                System.out.println(i);
                System.out.println(j);
            }
        }
        return false;
    }

    private void dfs(TreeNode root) {
        if (root==null) return;
        dfs(root.left);
        vals.add(root.val);
        dfs(root.right);
    }

    public static void main(String[] args) {
        ArrayList<Integer> arrayList = new ArrayList<>();
        arrayList.add(2);
        arrayList.add(3);
        arrayList.add(4);
        arrayList.add(5);
        arrayList.add(7);
        new FindTarget().dpt(5,arrayList,2);
    }
}
